import { getQuit, getQuitDetail } from '@/services/onboardAndLeave/quitManagement';

export default {
    namespace: 'quitManagement',
    state: {
        data: [],
        pagination: {
            current: 1,
            pageSize: 10,
            total: 0
        }
    },
    effects: {
        // 离职列表
        *fetchList({ payload }, { call, put }) {
            const result = yield call(getQuit, payload);
            if (result && result.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        data: result.data.rows,
                        pagination: {
                            pageSize: result.data.pageSize,
                            current: result.data.pageNo,
                            total: result.data.total
                        }
                    }
                });
            }
        },
        // 获取离职详情
        *getDetail({ payload, callback }, { call, put }) {
            const response = yield call(getQuitDetail, payload);
            if (response.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        userData: response.data
                    }
                });
            }
            callback(response);
        }
    },
    reducers: {
        save(state, { payload }) {
            return {
                ...state,
                ...payload
            };
        }
    }
};
